﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.SoldierArchives.BLL;
using Yipusoft.SoldierArchives.Model;

public partial class Police_TranslateDocument_TransferTreatNew : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }
    }

    void init()
    {
        lblYear.Text = DateTime.Now.Year.ToString();
        lblNumber.Text = TransferTreat.GetNewNumber().ToString();
        if (Request["id"] != null)
        {
            TransferTreatInfo model = TransferTreat.GetDetail(new Guid(Request["id"]));
            this.lblNumber.Text = model.Number.ToString();
            this.txtName.Text = model.SoldierName;
            this.txtSex.Text = model.Sex;
            this.txtOldDepartment.Text = model.OldDepartment;
            this.txtDateArmy.Text = model.DateArmy.ToString();
            this.txtRanger.Text = model.Ranger;
            this.txtNewDepartment.Text = model.NewDepartment;
            this.txtDataLetter.Text = model.DataLetter.ToString();
            this.Approver.Text = model.Approver;
            this.Undertaker.Text = model.Undertaker;
            this.Linkman.Text = model.Linkman;
            this.Remark.Text = model.Remark;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request["id"] == null)
        {
            int Number = int.Parse(this.lblNumber.Text);
            string SoldierName = this.txtName.Text;
            string Sex = this.txtSex.Text;
            string OldDepartment = this.txtOldDepartment.Text;
            DateTime DateArmy = DateTime.Parse(this.txtDateArmy.Text);
            string Ranger = this.txtRanger.Text;
            string NewDepartment = this.txtNewDepartment.Text;
            DateTime DataLetter = DateTime.Parse(this.txtDataLetter.Text);
            string Approver = this.Approver.Text;
            string Undertaker = this.Undertaker.Text;
            string Linkman = this.Linkman.Text;
            string Remark = this.Remark.Text;
            DateTime DateBook = DateTime.Now;
            string YearNo = this.lblYear.Text;
            string BookMan = User.Identity.Name;
            DateTime TimeLastModified = DateTime.Now;
            string UserLastModified = User.Identity.Name;

            TransferTreatInfo model = new TransferTreatInfo();
            model.Number = Number;
            model.SoldierName = SoldierName;
            model.Sex = Sex;
            model.OldDepartment = OldDepartment;
            model.DateArmy = DateArmy;
            model.Ranger = Ranger;
            model.NewDepartment = NewDepartment;
            model.DataLetter = DataLetter;
            model.Approver = Approver;
            model.Undertaker = Undertaker;
            model.Linkman = Linkman;
            model.Remark = Remark;
            model.DateBook = DateBook;
            model.YearNo = YearNo;
            model.BookMan = BookMan;
            model.TimeLastModified = TimeLastModified;
            model.UserLastModified = UserLastModified;

            Guid id = TransferTreat.Insert(model);
            if (id != Guid.Empty)
            {
                Prompt.Text = "提示：添加成功!";
            }
            else
            {
                Prompt.Text = "提示：添加失败!";
            }

        }
        else
        {
            string SoldierName = this.txtName.Text;
            string Sex = this.txtSex.Text;
            string OldDepartment = this.txtOldDepartment.Text;
            DateTime DateArmy = DateTime.Parse(this.txtDateArmy.Text);
            string Ranger = this.txtRanger.Text;
            string NewDepartment = this.txtNewDepartment.Text;
            DateTime DataLetter = DateTime.Parse(this.txtDataLetter.Text);
            string Approver = this.Approver.Text;
            string Undertaker = this.Undertaker.Text;
            string Linkman = this.Linkman.Text;
            string Remark = this.Remark.Text;
            DateTime TimeLastModified = DateTime.Now;
            string UserLastModified = User.Identity.Name;

            TransferTreatInfo model = TransferTreat.GetDetail(new Guid(Request["id"]));
            model.SoldierName = SoldierName;
            model.Sex = Sex;
            model.OldDepartment = OldDepartment;
            model.DateArmy = DateArmy;
            model.Ranger = Ranger;
            model.NewDepartment = NewDepartment;
            model.DataLetter = DataLetter;
            model.Approver = Approver;
            model.Undertaker = Undertaker;
            model.Linkman = Linkman;
            model.Remark = Remark;
            model.TimeLastModified = TimeLastModified;
            model.UserLastModified = UserLastModified;
            if (TransferTreat.Update(model))
            {
                Prompt.Text = "提示：修改成功!";
            }
            else
            {
                Prompt.Text = "提示：修改失败!";

            }
        }
    }
}
